Skip to content

[Otel] fix otel baggage prop#12665

Open
AgraVator wants to merge 5 commits intogrpc:masterfrom
AgraVator:otel-baggage-context
Open

[Otel] fix otel baggage prop#12665
AgraVator wants to merge 5 commits intogrpc:masterfrom
AgraVator:otel-baggage-context

Conversation

@AgraVator
Copy link
Contributor

No description provided.

@AgraVator AgraVator marked this pull request as ready for review February 26, 2026 11:11
@AgraVator AgraVator requested a review from ejona86 February 26, 2026 11:11
@Test
public void serverMetricsShouldRecordContextWithBaggage() {
// Mocks
DoubleHistogram serverCallDurationCounter = mock(DoubleHistogram.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only safe to mock classes under your control. Mocks break API guarantees and can do horrible things. Those can be addressed when you change your own class and it breaks a test. But if you don't own the class, you can't control it.

Collection<String> optionalLabels, List<OpenTelemetryPlugin> plugins,
@Nullable TargetFilter targetAttributeFilter) {
ContextPropagators contextPropagators,
@Nullable TargetFilter targetAttributeFilter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore indentation.

streamPlugins = Collections.unmodifiableList(streamPluginsMutable);
}
return new ServerTracer(OpenTelemetryMetricsModule.this, fullMethodName, streamPlugins);
Context context = contextPropagators.getTextMapPropagator().extract(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being done by the OpenTelemetryTracingModule and is being propagated via filterContext(), specifically so it can be used by the metrics module. If we want the full context, propagate that instead. I don't understand the goal here (and there's no description about why we're doing this in the PR description or a comment from what I can tell). And I'm doubly confused by using this context directly half the time and copying BAGGAGE_KEY into it other times.


void recordFinishedAttempt() {
Context otelContext = otelContextWithBaggage();
Context otelContext = otelContextWithBaggage(BAGGAGE_KEY.get());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no guaranteed Context as this point. I think this is only working because you're using in-process, which calls the StatsTraceContext on the calling thread. If the test used Netty instead, I suspect the baggage would no longer be found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants